//
//  BackController.swift
//  WeiBo001
//
//  Created by ZhiQiang Li on 16/7/23.
//  Copyright © 2016年 ZhiQiang Li. All rights reserved.
//

import UIKit

class BackController: UIViewController {
    override func loadView() {
        view = backImage
    }
    
    override func viewDidLoad() {
        setupUI()
    }
    
    //动画
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        self.headImage.snp_updateConstraints(closure: { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        })
        
        
             UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            // 对当前页面进行刷新
            self.view.layoutIfNeeded()
            
            }) { (_) -> Void in
                // 当上个动画完成后
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    
                    self.backLabel.alpha = 1
                    
                    }, completion: { (_) -> Void in
                        // 发送通知 切换根控制器为MainVc
                        NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootViewControllerNoti, object: "welcome")
                })
        }

    }
    
       //设置视图
   func setupUI(){
    //背景图片
   view.addSubview(headImage)
    view.addSubview(backLabel)

    //设置约束
    headImage.snp_makeConstraints { (make) -> Void in
        make.width.height.equalTo(90)
        make.centerX.equalTo(view)
        make.top.equalTo(view).offset(400)
    }
    backLabel.snp_makeConstraints { (make) -> Void in
         make.centerX.equalTo(view)
        make.top.equalTo(headImage.snp_bottom).offset(16)
    }
    
    
    }
    
    
    //懒加载控件
    //背景图片
  private  lazy var backImage:UIImageView = UIImageView(imageName: "ad_background")
    //headImageView
    private lazy var headImage:UIImageView = {
        let img = UIImageView(imageName: "avatar_default_big")
     img.sh_setImage(CZUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        img.layer.borderColor = ThemeColor.CGColor
        img.layer.borderWidth = 2
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
        
    }()
    
    //"欢迎回来"
    private lazy var backLabel: UILabel = {
        let lab = UILabel(textColor: UIColor.blackColor(), textFont: 18)
        lab.text = "欢迎回来"
        lab.textAlignment = .Center
        lab.alpha = 0
        return lab
    }()
   
    

}
